﻿using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;


namespace BubbleSurvival
{
    /// <summary>
    /// A fejlesztés során használt interface
    /// </summary>
    public class DeveloperInterfaceManager
    {

        SpriteFont developerUIFont;         // egy font
        MouseState prevMouseState;          // egér állapotánka rögzítéséhez
        Vector2 mouseCoords;                // koordinatak

        float fPS;                          // a játék FPS-e
        float lastFPS;                      // FPS méréséhez szükséges
        float timeSinceLastSecond;          // FPS méréséhez szükséges

        // Konstruktor
        public DeveloperInterfaceManager(SpriteFont spriteFont)
        {
            fPS = 0;
            lastFPS = 0;
            timeSinceLastSecond = 0;
            prevMouseState = new MouseState();
            mouseCoords = Vector2.Zero;
            developerUIFont = spriteFont; // Game.Content.Load<SpriteFont>(@"Theme0\Fonts\smallFont");
        }

        /// <summary>
        /// Update.
        /// </summary>
        public void Update(GameTime gameTime)
        {

            // egérmutató koordinátáinak beállítása
            MouseState currMouseState = Mouse.GetState();
            if (currMouseState.X != prevMouseState.X || currMouseState.Y != prevMouseState.Y)
            {
                mouseCoords = new Vector2(currMouseState.X, currMouseState.Y);
            }
            prevMouseState = currMouseState;

            // FPS mérése
            timeSinceLastSecond += gameTime.ElapsedGameTime.Milliseconds;

            if (timeSinceLastSecond > 1000)
            {
                timeSinceLastSecond = 0;
                lastFPS = fPS;
                fPS = 0;
            }

        }

        /// <summary>
        /// Draw.
        /// </summary>
        public void Draw(SpriteBatch spriteBatch, Vector2 pos, float zoom, Vector2 mouseVPos)
        {

            // FPS méréshez                                
            fPS++;

            // info-k kiírása
            spriteBatch.DrawString(developerUIFont, "Mouse coords on Screen: " + mouseCoords,
                                new Vector2(5, 5),
                                Color.LightGray);
            spriteBatch.DrawString(developerUIFont, "Mouse coords on World:  " + mouseVPos,
                                new Vector2(5, 20),
                                Color.LightGray);
            spriteBatch.DrawString(developerUIFont, "Camera pos on World:   " + pos,
                                new Vector2(5, 35),
                                Color.LightGray);
            spriteBatch.DrawString(developerUIFont, "Zoom: " + zoom,
                                new Vector2(5, 50),
                                Color.LightGray);
            spriteBatch.DrawString(developerUIFont, "FPS: " + lastFPS,
                                new Vector2(5, 80),
                                Color.LightGray);

        }

    }

}